package com.actionscriptclass.dataholder
{
	public class TimerData implements IDataHolder
	{
		  // main array holder for delay,function and repead
		  private var _timerDataArray:Array;
		  //proccesed array holder for delay,function and repead
	      private var _mainArray:Array;
	      //repeat number of TimerInvoker
		  private var _repeat:uint;
		 
		 public function TimerData()
	     {
			_timerDataArray=new Array();
			_mainArray=new Array();
	     }
		 
		 //adding new data 
		 public function addData(dataObject:Object):void
		 {
		    _timerDataArray.push([dataObject['sek'],dataObject['repeat'],dataObject['func']]);	
		 }
		   
		//getting current delay
		 public function getDelay(num:uint):uint
		 {
		 	return _mainArray[num][0]
		 }
		 
		 public function setDelay(value:uint,position:uint):void
		 {
		 	
		 }
		 
		 //execution current function
		 public function functionExec(num:uint):void
		 {
		 	_mainArray[num][1]();
		 }
		 
		 //procesing data give by the user  
		 public function processData():void
		 {
		   	 //ukupan broj ponavljanja u delay arrayu
		 	   var count:uint=0 	 	
	           // prebrojava ukupan broj ponavljanja u 
	           for(var i:uint=0;i<_timerDataArray.length;i++)
	 		   {
	 				count+=_timerDataArray[i][1]
	 		   }
	 	 
	 		   var countArrayIteration:uint=0;
	 		   var counterSize:uint=_timerDataArray[countArrayIteration][1];
	 		   //for petlja koja popunjava _mainArray
	 		    for(var ie:uint=0;ie<count;ie++)
	 			{ 
	 		 		//kad dođe do kraja prvog addItem onda se preko else prebacuje na drugi i tako dok se ne izlista cijeli array
	 			    if( ie <counterSize)
	 			    {
	 			   	      _mainArray.push([_timerDataArray[countArrayIteration][0],_timerDataArray[countArrayIteration][2]]);
	 			    }
	 			    else  
	 			    {
	 			 		 
	 				    countArrayIteration++;
	 			        _mainArray.push([_timerDataArray[countArrayIteration][0],_timerDataArray[countArrayIteration][2]]);
	 				     
	 				     counterSize=0;
	 			   	    for(var iv:uint=0;iv< countArrayIteration+1 ;iv++)
			 			{
			 				counterSize+=_timerDataArray[iv][1]
			 			}  	 
			 	    } 
	 		     }
	  
	 		    repeat = count
	 	  }
		 //number of repeat 
		 public function set repeat(num:uint):void
		 {
		 	_repeat=num
		 }
		   
		 public function  get repeat():uint
		 {
		  	 return  _repeat
		 }
		 
		 //lenght of data that is stored, 0 in TimerData because no data are stored
		 public function get dataHolderData():*
		 {
			 return 0;
		 }
		  
		 //access to data that is stored, 0 in TimerData because no data are stored 
		 public function getValue():*
		 {
		  
		 }
	   
	 }
}